package com.bjsxt.shop.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class FileUtil
{
	
	
	public String readFile(File soufile)
	{
		try
		{
			return this.readFile(new FileInputStream(soufile));
		} catch (FileNotFoundException e)
		{
			ConstatFinalUtil.LOGGER.error("读取文件失败",e);
		}
		return "";
				 
	}
	
	public String readFile(InputStream is)
	{
		StringBuffer sb = new StringBuffer();
		BufferedReader br = null;
		try
		{
			br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
			String line = "";
			while((line=br.readLine())!=null)
			{
				line = line.trim();
				if("".equalsIgnoreCase(line)||line.startsWith("//"))
				{
					continue;
				}
				sb.append(line);
			}
			
		} catch (Exception e)
		{
			ConstatFinalUtil.LOGGER.error("读取流失败了",e);
		}finally
		{
			try
			{
				br.close();
			} catch (IOException e)
			{
			ConstatFinalUtil.LOGGER.error("关闭流失败了");

			}
		}
		return sb.toString();
	}
	
	public static void main(String[] args)
	{
		FileUtil fu = new FileUtil();
		File soufile = new File("D:/vacation/shop/shop-common/src/main/resources/resoureInfo.json");
		String str = fu.readFile(soufile);
		System.out.println(str);
		
		
	}
}
